#include <sys/wait.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int system(const char *cmdstring){
    pid_t pid;
    int status;
    if((pid = fork()) < 0){
        printf("%s\n", strerror(errno));
        printf("fork error!\n");
        exit(0);
    }else if(pid == 0){
        execl("/bin/sh", "sh", "-c", cmdstring, NULL);
        _exit(127);
        //防止复制的I/O缓冲区在子进程中被重洗
    }else{
        while(waitpid(pid, &status, 0) < 0){
            if(errno != EINTR){
                status = -1;
                break;
            }
        }
    }

    return status;
}